package com.theaf.core.utils;


import com.alibaba.dubbo.config.annotation.Reference;
import com.theaf.core.api.OrderNoComService;
import org.springframework.context.annotation.Configuration;

/**
* 订单号工具.
* @author huangligui
* @date 2015-11-20
*
*/
@Configuration
public class OrdernoHelper {
	 @Reference
	 private static OrderNoComService orderNoComService;
	 
	/**
	*
	* 根据业务类型生成订单号。
	* 每天每个类型都从1开始计数。<br/>
	* 订单号规则为:类型+年月日+计数。<br/>
	* 比如 新车销售单：XCXS-201511200001; <br/>
	*
	* @param type 订单号前缀，业务标识
	* @return
	* @throws Exception
	* String    返回类型
	* @throws
	*/
	 public static String getOrderNo(String type) throws Exception
	 {
		 if (type == null) {
			 throw new RuntimeException("类型不能为空!");
		 }
		 String orderno = orderNoComService.makeOrderNo(type);
		 if (orderno == null) {
			 throw new RuntimeException("不能生成订单号,确定服务正常之后重试!");
		 }
		 return orderno;
	 }
}
